package com.CST.controller.cb;

import com.CST.common.api.ResultObject;
import com.CST.dto.cb.InSourceDTO;
import com.CST.service.cb.IEtlAccvouchService;
import com.CST.service.cb.IEtlInComeSourceService;
import com.CST.service.cb.IEtlIncomeinsourceService;
import com.CST.service.cb.IEtlIncomeoutsourceService;
import com.CST.util.PageHelperTool;
import com.CST.vo.cb.InSourceVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/etlInComeSource")
@Api(tags = {"收入数据"})
public class EtlInComeSourceController {

    @Autowired
    private IEtlIncomeinsourceService etlIncomeinsourceService;

    @Autowired
    private IEtlIncomeoutsourceService etlIncomeoutsourceService;
    
    @Autowired
    private IEtlInComeSourceService etlInComeSourceService;
    
    @Autowired
    private IEtlAccvouchService etlAccvouchService;

//    @PostMapping("/listEtlInComeInSource")
//    @ApiOperation("获取住院收入数据")
//    public ResultObject listEtlInComeInSource(@RequestBody EtlIncomeinsource2021 etlIncomeinsource2021) {
//        return null;
//    }


    @PostMapping("/listEtlInComeOutSource")
    @ApiOperation("获取门诊收入数据列表")
    public ResultObject listEtlInComeOutSource(@RequestBody InSourceDTO inSourceDTO) {
        return etlIncomeoutsourceService.listEtlInComeOutSource(inSourceDTO);
    }

    @PostMapping("/listEtlInComeInSource")
    @ApiOperation("获取住院收入列表")
    public ResultObject listEtlInComeInSource(@RequestBody InSourceDTO inSourceDTO) {
        return etlIncomeinsourceService.listEtlInComeInSource(inSourceDTO);
    }

    @PostMapping("/listEtlAccvouchSource")
    @ApiOperation("获取非HIS收入列表")
    public ResultObject listEtlAccvouchSource(@RequestBody InSourceDTO inSourceDTO){
        return etlAccvouchService.listEtlAccvouchSource(inSourceDTO);
    }

    @PostMapping("/listEtlInComeSource")
    @ApiOperation("A 获取收入列表，获取值根据传入的开单/执行科室的编码集合确定")
    public ResultObject listEtlInComeSource(@RequestBody InSourceDTO inSourceDTO) {
        return etlInComeSourceService.listEtlInComeSource(inSourceDTO);
    }
    
    @PostMapping("/listInComeSource")
    @ApiOperation("B 获取收入列表，根据传入值进行具体查询")
    public ResultObject listInComeSource(@RequestBody InSourceDTO inSourceDTO){
        List<InSourceVO> inSourceVOList = etlInComeSourceService.listInComeSource(inSourceDTO);
        PageInfo<InSourceVO> inSourceVOPageInfo = PageHelperTool.excutePageInfo(inSourceVOList, inSourceDTO.getPageNum(), inSourceDTO.getPageSize());
        BigDecimal amount = BigDecimal.ZERO;
        for (InSourceVO inSourceVO : inSourceVOList){
            amount.add(inSourceVO.getAmount());
        }
        Map map = new HashMap();
        map.put("data", inSourceVOPageInfo);
        map.put("amount", amount);
        return ResultObject.successReturn(map);
    }
    
//    @PostMapping("/getUnLinkHisCodeWithBill")
//    @ApiOperation("获取开单科室未关联的his编码")
//    public ResultObject getUnLinkHisCodeWithBill(@RequestBody InSourceDTO inSourceDTO){
//        return etlInComeSourceService.getUnLinkHisCodeWithBill(inSourceDTO);
//    }
//
//    @PostMapping("/getUnLinkHisCodeWithExecutive")
//    @ApiOperation("获取执行科室未关联的his编码")
//    public ResultObject getUnLinkHisCodeWithExecutive(@RequestBody InSourceDTO inSourceDTO){
//        return etlInComeSourceService.getUnLinkHisCodeWithExecutive(inSourceDTO);
//    }

    /**
     * 重写
     * xnd
     * 现在是在base in come 那张表里去搜索已关联未关联
     * @param inSourceDTO
     * @return
     */
    @PostMapping("/getUnLinkHisCodeWithBill")
    @ApiOperation("获取开单科室未关联的his编码")
    public ResultObject getUnLinkHisCodeWithBill(@RequestBody InSourceDTO inSourceDTO){
        return etlInComeSourceService.getBaseInCome(inSourceDTO);
    }

    /**
     * 重写
     * xnd
     * 现在是在base in come 那张表里去搜索已关联未关联
     * @param inSourceDTO
     * @return
     */
    @PostMapping("/getUnLinkHisCodeWithExecutive")
    @ApiOperation("获取执行科室未关联的his编码")
    public ResultObject getUnLinkHisCodeWithExecutive(@RequestBody InSourceDTO inSourceDTO){
        return etlInComeSourceService.getBaseInComeTwo(inSourceDTO);
    }
}
